package com.cognizant.app.ui.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.cognizant.app.R;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import us.zoom.sdk.JoinMeetingOptions;
import us.zoom.sdk.MeetingService;
import us.zoom.sdk.ZoomSDK;

public class InputFragment extends Fragment {
    private Unbinder unbinder;
    @BindView(R.id.num_input)
    EditText numInput;
    @BindView(R.id.go)
    Button goImageBtn;
    @Override
    public View onCreateView(LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.view_pager_input, null);
        ButterKnife.bind(this,view);
        unbinder = ButterKnife.bind(this,view);
        EventBus.getDefault().register(this);
        return view;
    }
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(String qrCode) {
        numInput.setText(qrCode);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
        EventBus.getDefault().unregister(this);
    }

    @OnClick(R.id.go)
    public void onClickBtnJoinMeeting(){
        String meetingNo = numInput.getText().toString().trim();
        ZoomSDK zoomSDK = ZoomSDK.getInstance();

        if(!zoomSDK.isInitialized()) {
            Toast.makeText(getActivity(), "ZoomSDK has not been initialized successfully", Toast.LENGTH_LONG).show();
            return;
        }
        MeetingService meetingService = zoomSDK.getMeetingService();

        JoinMeetingOptions opts = new JoinMeetingOptions();
        int ret = meetingService.joinMeeting(getActivity(), meetingNo, "Test", null, opts);
    }
}
